package com.clouddms.service.security;

import java.util.Base64;

/**
 * 加密操作结果
 * 
 * @author Cloud-DMS Team
 * @version 1.0.0
 */
public class EncryptionResult {
    private boolean success;
    private String message;
    private String encryptedHash;
    private byte[] iv;
    private String keyId;
    private long encryptionTime;

    // 私有构造函数
    private EncryptionResult() {
        this.encryptionTime = System.currentTimeMillis();
    }

    /**
     * 创建成功的加密结果
     */
    public static EncryptionResult success(String encryptedHash, byte[] iv, String keyId) {
        EncryptionResult result = new EncryptionResult();
        result.success = true;
        result.message = "文件加密成功";
        result.encryptedHash = encryptedHash;
        result.iv = iv;
        result.keyId = keyId;
        return result;
    }

    /**
     * 创建失败的加密结果
     */
    public static EncryptionResult failure(String message) {
        EncryptionResult result = new EncryptionResult();
        result.success = false;
        result.message = message;
        return result;
    }

    // Getters
    public boolean isSuccess() {
        return success;
    }

    public String getMessage() {
        return message;
    }

    public String getEncryptedHash() {
        return encryptedHash;
    }

    public byte[] getIv() {
        return iv;
    }

    public String getIvBase64() {
        return iv != null ? Base64.getEncoder().encodeToString(iv) : null;
    }

    public String getKeyId() {
        return keyId;
    }

    public long getEncryptionTime() {
        return encryptionTime;
    }

    @Override
    public String toString() {
        return String.format("EncryptionResult{success=%s, message='%s', hash='%s'}", 
            success, message, encryptedHash);
    }
}